home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiscKit1.7.1 / MiscKit / Palettes / MiscPaperViewPalette / MiscPaperView.subproj / MiscColorView.m < prev    next >
Text File  |  1995-07-20  |  3KB  |  136 lines

  1. //        Written by Thomas Engel Copyright (c) 1995 by Thomas Engel.
  2. //                Version 1.0.  All rights reserved.
  3. //
  4. //        This notice may not be removed from this source code.
  5. //
  6. //    This object is included in the MiscKit by permission from the author
  7. //    and its use is governed by the MiscKit license, found in the file
  8. //    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  9. //    for a list of all applicable permissions and restrictions.
  10. //    
  11.  
  12. #import <misckit/MiscColorView.h>
  13.  
  14. #define MISC_COLORVIEW_VERSION 0
  15. #define MISC_COLORVIEW_CLASSNAME "MiscColorView"
  16.  
  17.  
  18. @implementation  MiscColorView
  19.  
  20. + initialize
  21. {
  22.     // Initialize the current version number which is used when archiving 
  23.     // objects. This way we will be able to read all versions if we are 
  24.     // careful.
  25.  
  26.     if( self == [MiscColorView class] )
  27.         [self setVersion:MISC_COLORVIEW_VERSION];
  28.         
  29.     return self;
  30. }
  31.  
  32. - initFrame:(const NXRect *)frameRect
  33. {
  34.     // Designated initilizer. We will set allow resizing by default and
  35.     // we will draw in Lightgray if we have to swap 'nil' in.
  36.  
  37.     self = [super initFrame:frameRect];
  38.     if( !self ) return self;
  39.  
  40.     // By default we have a white background and don't focus on the
  41.     // desktops background.
  42.  
  43.     backgroundColor = NXConvertRGBToColor( 1.0, 1.0, 1.0 );
  44.  
  45.     return self;
  46. }
  47.  
  48. - setBackgroundColor:(NXColor)color
  49. {
  50.     backgroundColor = color;
  51.     return self;
  52. }
  53.  
  54. - (NXColor)backgroundColor
  55. {
  56.     return backgroundColor;
  57. }
  58.  
  59. - setUseSameColorAsDesktop:(BOOL)flag
  60. {
  61.     sameColorAsDesktop = flag;
  62.     return self;
  63. }
  64.  
  65. - (BOOL)hasSameColorAsDesktop
  66. {
  67.     return sameColorAsDesktop;
  68. }
  69.  
  70. - drawSelf:(const NXRect *)rects :(int)rectCount
  71. {
  72.     const char *    defaultVal;
  73.     float    red;
  74.     float    green;
  75.     float    blue;
  76.     
  77.     if( sameColorAsDesktop )
  78.     {
  79.         // Read the desktops color form the defaults database.
  80.  
  81.         defaultVal = NXReadDefault( "NeXT1", "BackgroundColor" );
  82.  
  83.         if( defaultVal != NULL )
  84.             sscanf( defaultVal, "%f %f %f",&red, &green, &blue );
  85.         
  86.         // If there is no default we will take a shade of blue.
  87.         // This seems to be the color NeXT uses as a default.
  88.  
  89.         else
  90.         {    
  91.             red = 0.333333;
  92.             green = 0.333333;
  93.             blue = 0.466666;
  94.         }
  95.         NXSetColor( NXConvertRGBToColor( red, green, blue ));    }
  96.     else    
  97.         NXSetColor( backgroundColor );
  98.  
  99.     NXRectFill( &bounds );
  100.     return self;
  101. }
  102.  
  103. - read:(NXTypedStream *)stream
  104. {
  105.     int  version;
  106.   
  107.     [super read:stream];
  108.     
  109.     version = NXTypedStreamClassVersion( stream, MISC_COLORVIEW_CLASSNAME );
  110.     
  111.     switch( version )
  112.     {
  113.         case 0:
  114.             backgroundColor = NXReadColor( stream );
  115.             NXReadType( stream, "c", &sameColorAsDesktop );
  116.             break;
  117.         
  118.         default:
  119.             break;
  120.     }
  121.  
  122.     return self;
  123. }
  124.  
  125. - write:(NXTypedStream *)stream
  126. {
  127.     [super write:stream];
  128.  
  129.     NXWriteColor( stream, backgroundColor );
  130.     NXWriteType( stream, "c", &sameColorAsDesktop );
  131.  
  132.     return self;
  133. }
  134.  
  135. @end
  136.